package com.ccb.filter;

import java.util.HashSet;
import java.util.List;

public class RecordFilter {
	private String projectName;
	private HashSet<String> includeSet;
	private HashSet<String> excludeSet;
	//1:includeSet is used;
	//2:excludeSet is used;
	//0:both not been used;
	private int useFlag = 0;
	
	public String getProjectName() {
		return projectName;
	}

	protected void setProjectName(String projectName) {
		this.projectName = projectName;
	}
	
	protected void add2IncludeList(List<String> includes){
		if (includeSet==null) includeSet = new HashSet<String>();
		includeSet.addAll(includes);
	}
	
	protected void add2ExcludeList(List<String> excludes){
		if (excludeSet==null) excludeSet = new HashSet<String>();
		excludeSet.addAll(excludes);
	}
	
	protected int getUseFlag() {
		return useFlag;
	}
	
	protected void resetUseFlag() {
		if (includeSet!=null) {
			useFlag = 1;
			return;
		}
		if (excludeSet!=null) {
			useFlag = 2;
			return;
		}
	}
	
	public boolean accept(String key){
		switch(getUseFlag()){
			case 1: 
				if (includeSet.contains(key)) {
					return true;
				} else {
					return false;
				}
			case 2:
				if (excludeSet.contains(key)) {
					return false;
				} else {
					return true;
				}
			case 0: return true;
			default: return true;
		}
	}
}
